package cn.qqcn.emp.cotroller;

import cn.qqcn.common.vo.Result;
import cn.qqcn.emp.entity.Dept;
import cn.qqcn.emp.entity.Emp;
import cn.qqcn.emp.service.EmpService;
import cn.qqcn.emp.vo.EmpQuery;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/emp")
public class Empcotroller {

    @Autowired
    private EmpService empService;

    @PostMapping("/addemp")
    @ResponseBody
    public Result<Object> addEmp(Emp emp) {
        empService.addEmp(emp);
        return Result.success("新增人员成功！");
    }

    @GetMapping("/list")
    @ResponseBody
    public Result<Object> getEmplist(EmpQuery param){
        List<Emp> list = empService.getEmpList(param);
        Long count  = empService.countEmplist(param);
        return Result.success(list,count);
    }

    @PostMapping("/{ids}")
    @ResponseBody
    public Result<Object> deletempByids(@PathVariable("ids") String ids) {
        empService.deletempByids(ids);
        return Result.success("删除成功！");
    }

    @PutMapping("/update")
    @ResponseBody
    public Result<Object> updateEmp(Emp emp) {
        empService.updateEmp(emp);
        return Result.success("修改员工信息成功！");
    }

}
